using System;
using System.Collections.Generic;
using System.Text;
using MSRI.HelperClasses;
using System.Globalization;
using Instedd.Labs.Geo.Library.Kml;

namespace Instedd.Labs.Geo.Library.Sms
{
    public class SmsExtension
    {
        public const string LocalNumber = "Local";

        internal SmsExtension()
        { }

        public SmsExtension(SmsClass smsClasss, LatLong latLong, string message, string senderName, string receivingNumber)
        {
            this.sms = smsClasss;
            this.location = latLong;
            this.message = message;
            this.senderName = senderName;
            this.receivingNumber = receivingNumber;
        }

        private SmsClass sms;

        public SmsClass Sms
        {
            get { return sms; }
        }

        private LatLong location;

        public LatLong Location
        {
            get { return location; }
        }

        private string message;

        public string Message
        {
            get { return message; }
        }

        private string senderName;

        public string SenderName
        {
            get { return senderName; }
        }

        public override string ToString()
        {
            return string.Format("SMS Extension: SenderName='{0}', Message='{1}', LatLong='{2}'", 
                SenderName, Message, location);
        }

        private SmsExtension answeredMessage;

        public SmsExtension AnsweredMessage
        {
            get { return answeredMessage; }
            set { answeredMessage = value; }
        }

        public string GetMessageIdAsString()
        {
            return this.sms.MessageID.ToString(string.Empty, CultureInfo.InvariantCulture);
        }

        public SmsExtension Reply(string senderName, string message)
        {
            return Reply(senderName, message, null);
        }

        public SmsExtension Reply(string senderName, string message, LatLong location)
        {
            SmsClass sms = new SmsClass(this.sms.Number, message);
            SmsExtension answer = new SmsExtension(sms, location, message, senderName, this.sms.Number);
            answer.AnsweredMessage = this;
            return answer;
        }

        private string receivingNumber;

        public string ReceivingNumber
        {
            get { return receivingNumber; }
            set { receivingNumber = value; }
        }

        public bool IsReplay { get { return this.answeredMessage != null; } }
    }
}
